// eslint-disable-next-line import/no-extraneous-dependencies
import {LockOutlined, UserOutlined } from '@ant-design/icons';
import { Button, Form, Input, message } from 'antd';
import React from 'react';
import "./rightCol.css"
import {history} from 'umi';

// eslint-disable-next-line react/prefer-stateless-function
class  RightCol extends  React.Component{
  // eslint-disable-next-line no-useless-constructor
  constructor(props) {
    super(props);
    console.log("constructor");
  }

  onFinish = (values) => {
    console.log(values);
    let url2 ="http://127.0.0.1:8089/login?";
    const { username="",password="" }=values;
    url2= url2 + "username="+String(values.username);
    url2= url2 + "&password="+String(values.password);
    const url="http://127.0.0.1:8089/login?username=admin&password=88888888";
    console.log(url2)
    fetch(url2,
      {
        method:'POST',
        headers: { Authorization: localStorage.getItem('Authorization') }
      })
      .then(response => response.json())
      .then((res)=>{
        const {code=0,data={},msg}=res;
        const {token}=data;
        if(res.code!==0){
          message.error(res.message);
          return;
        }
        // localStorage.setItem('Authorization','Bearer '+res.data.token)
        message.info(res.msg);
        history.push('/Demo2')
    });

  };

  render() {
    return (
      <>
        <div id="login_title">医疗系统登录</div>
        <div id="login_content">
          <Form
            name="normal_login"
            className="login-form"
            initialValues={{
              username:"admin",
              password:"88888888"
          }}
            onFinish={this.onFinish}
          >
            <h1 id="form-title">用户管理</h1>
            <Form.Item
              className="fromItemStyle"
              name="username"
              rules={[{ required: true, message: '输入你的用户名！！！', },]}
            >
              <Input prefix={<UserOutlined className="inputStyle" />} placeholder="Username" />
            </Form.Item>
            <Form.Item
              className="fromItemStyle"
              name="password"
              rules={[{ required: true, message: '输入正确密码！！！', },]}
            >
              <Input
                prefix={<LockOutlined className="inputStyle" />}
                type="password"
                placeholder="password"
              />
            </Form.Item>
            <Form.Item
              className="fromItemStyle"
            >
              <Button type="primary" htmlType="submit" className="login-form-button">
                登录
              </Button>
            </Form.Item>
          </Form>
        </div>

      </>
    );
  };
}
export default RightCol;
